package sxe.core.struct;

import snobject.snObject;
import snobject.snObjectArgList;
import snobject.snString;
import snobject.snStruct;
import step.EvaluationFailure;
import step.FunctionWrapper;

public class create extends FunctionWrapper {

	@Override
	public snObject Call(snObjectArgList argv) throws EvaluationFailure,
			ClassCastException, ArrayIndexOutOfBoundsException {
		snStruct snstruct = new snStruct();
		
		snString snKey = null;
		snObject snVal = null;
		
		while(argv.hasNext()){
			if(snKey==null){
				snKey = argv.popString();
			}
			else if(snVal==null){
				snVal = argv.popObject();
				snstruct.put(snKey, snVal);
				snKey = null;
				snVal = null;
			}
		}
		
		if(snKey!=null){
			// wrong number of arguments...
			throw new ArrayIndexOutOfBoundsException();
		}
		
		return snstruct;
	}

}
